package pam.security;

import java.util.Iterator;
import java.util.List;

import pam.core.XMLObject;

/**
 * 系统用户类
 */
public class User implements XMLObject {

	private static final long serialVersionUID = -2994807129976732389L;

	private String username;

	private String title;

	private String password;

	private List roles;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List getRoles() {
		return roles;
	}

	public void setRoles(List roles) {
		this.roles = roles;
	}

	public String toXML() {

		StringBuffer sb = new StringBuffer();
		sb.append("<User>");

		sb.append("<Username>");
		sb.append(getUsername());
		sb.append("</Username>");

		sb.append("<Title>");
		sb.append(getTitle() == null ? "" : getTitle());
		sb.append("</Title>");

		List list = getRoles();
		if (list != null && list.size() > 0) {
			sb.append("<Role-List>");

			Iterator iterator = list.iterator();

			while (iterator.hasNext()) {
				Role role = (Role) iterator.next();
				if (role == null) {
					continue;
				}
				sb.append(role.toXML());
			}

			sb.append("</Role-List>");

		}

		sb.append("</User>");

		return sb.toString();

	}

}
